package com.xfdmao.fcat.coin.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xfdmao.fcat.coin.constant.CoinConstant;
import com.xfdmao.fcat.coin.entity.ContractMatch;
import com.xfdmao.fcat.coin.entity.Token;
import com.xfdmao.fcat.coin.huobi.contract.api.HbdmClient;
import com.xfdmao.fcat.coin.huobi.contract.api.HbdmRestApiV1;
import com.xfdmao.fcat.coin.huobi.contract.api.IHbdmRestApi;
import com.xfdmao.fcat.coin.service.ContractMatchService;
import com.xfdmao.fcat.coin.service.TokenService;
import com.xfdmao.fcat.common.controller.BaseController;
import com.xfdmao.fcat.common.util.JsonUtil;
import org.apache.http.HttpException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by fier on 2017/11/28.
 */
@RestController
@RequestMapping("contractMatch")
public class ContractMatchController extends BaseController<ContractMatchService, ContractMatch,Integer> {
    private static Logger logger = Logger.getLogger(ContractMatchController.class);
    @Value("${spring.profiles.active}")
    public String active;
    /**
     * // 合约接口地址 "https://api.hbdm.com";//火币api接口地址https://api.hbdm.com;
     */
    @Value("${huobi.contract.url_prex}")
    public String url_prex;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private ContractMatchService contractMatchService;
    //@GetMapping(value = "/save")
    public JSONObject queryContractMatchHistory(){
        List<Token> tokens = tokenService.selectListAll();
        for(Token token:tokens){
            IHbdmRestApi futureGetV1 = new HbdmRestApiV1(url_prex);
            IHbdmRestApi futurePostV1 = new HbdmRestApiV1(url_prex, token.getApiKey(), token.getApiSecret());
            String matchresults;
            try {
                // 获取合约历史委托
                matchresults = futurePostV1.futureContractMatchresults("BTC", "0", "90", "", "1", "50");
                // matchresults = "{\"status\":\"ok\",\"data\":{\"trades\":[{\"match_id\":14569402953,\"order_id\":6145283831,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":11566.33,\"trade_turnover\":100,\"trade_fee\":-0.000002593735437256,\"offset_profitloss\":0,\"create_date\":1565676961168,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14397802010,\"order_id\":6145283825,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":4,\"trade_price\":11555,\"trade_turnover\":400,\"trade_fee\":-0.000010385114668974,\"offset_profitloss\":-0.0001640802134688,\"create_date\":1565542542947,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14397802010,\"order_id\":6145283825,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":1,\"trade_price\":11555,\"trade_turnover\":100,\"trade_fee\":-0.000002596278667243,\"offset_profitloss\":-0.0000410200533672,\"create_date\":1565542542947,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14395469841,\"order_id\":6145283824,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11610.03,\"trade_turnover\":500,\"trade_fee\":-0.000012919863256167,\"offset_profitloss\":0,\"create_date\":1565541012480,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14375172356,\"order_id\":6145283822,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":11594.35,\"trade_turnover\":500,\"trade_fee\":-0.000012937335857551,\"offset_profitloss\":-0.000184066996197,\"create_date\":1565525926135,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14373468501,\"order_id\":6145283821,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11644.05,\"trade_turnover\":500,\"trade_fee\":-0.000012882115758692,\"offset_profitloss\":0,\"create_date\":1565524801484,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14367272678,\"order_id\":6145283820,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":11491.61,\"trade_turnover\":500,\"trade_fee\":-0.000013053001276583,\"offset_profitloss\":-0.000088380286542,\"create_date\":1565520308053,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14363423512,\"order_id\":6145283819,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11515,\"trade_turnover\":500,\"trade_fee\":-0.00001302648719062,\"offset_profitloss\":0,\"create_date\":1565517614334,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14325015913,\"order_id\":6145283817,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":11526,\"trade_turnover\":500,\"trade_fee\":-0.000013014055179593,\"offset_profitloss\":0.0001673364286635,\"create_date\":1565487907460,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14318216507,\"order_id\":6145283810,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11481.71,\"trade_turnover\":500,\"trade_fee\":-0.000013064256108192,\"offset_profitloss\":0,\"create_date\":1565483403709,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14172095852,\"order_id\":6145283808,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12051.75,\"trade_turnover\":500,\"trade_fee\":-0.000012446325222478,\"offset_profitloss\":-0.000175290225971,\"create_date\":1565379001919,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14170652717,\"order_id\":6145283807,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":3,\"trade_price\":12102.89,\"trade_turnover\":300,\"trade_fee\":-0.000007436240435135,\"offset_profitloss\":0,\"create_date\":1565378102045,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14170652717,\"order_id\":6145283807,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":12102.88,\"trade_turnover\":100,\"trade_fee\":-0.000002478748859775,\"offset_profitloss\":0,\"create_date\":1565378102045,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14170652717,\"order_id\":6145283807,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":12102.88,\"trade_turnover\":100,\"trade_fee\":-0.000002478748859775,\"offset_profitloss\":0,\"create_date\":1565378102045,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14162822503,\"order_id\":6145283803,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":11983.41,\"trade_turnover\":500,\"trade_fee\":-0.000012517305174403,\"offset_profitloss\":-0.0000787684329705,\"create_date\":1565372702045,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14162299250,\"order_id\":6145283802,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"open\",\"trade_volume\":2,\"trade_price\":11960.83,\"trade_turnover\":200,\"trade_fee\":-0.000005016374281717,\"offset_profitloss\":0,\"create_date\":1565372364379,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14162299250,\"order_id\":6145283802,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"open\",\"trade_volume\":3,\"trade_price\":11960.83,\"trade_turnover\":300,\"trade_fee\":-0.000007524561422576,\"offset_profitloss\":0,\"create_date\":1565372364379,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14111471755,\"order_id\":6145283801,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12116.74,\"trade_turnover\":500,\"trade_fee\":-0.000012379567441407,\"offset_profitloss\":0.0001713308562045,\"create_date\":1565340306443,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14110844899,\"order_id\":6145283800,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12066.64,\"trade_turnover\":500,\"trade_fee\":-0.000012430966698268,\"offset_profitloss\":0,\"create_date\":1565339938612,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14110832586,\"order_id\":6145283799,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12070.51,\"trade_turnover\":500,\"trade_fee\":-0.000008284654086695,\"offset_profitloss\":-0.0002065529328595,\"create_date\":1565339932254,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":14110526979,\"order_id\":6145283798,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12131,\"trade_turnover\":500,\"trade_fee\":-0.000012365015250185,\"offset_profitloss\":0,\"create_date\":1565339747082,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14110514070,\"order_id\":6145283797,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12135.28,\"trade_turnover\":500,\"trade_fee\":-0.000012360654224706,\"offset_profitloss\":-0.0001798383404535,\"create_date\":1565339740581,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14110321747,\"order_id\":6145283796,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12188.48,\"trade_turnover\":500,\"trade_fee\":-0.00001230670272257,\"offset_profitloss\":0,\"create_date\":1565339622705,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14110307369,\"order_id\":6145283795,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":4,\"trade_price\":12172,\"trade_turnover\":400,\"trade_fee\":-0.000006572461386789,\"offset_profitloss\":-0.00017068293666,\"create_date\":1565339616002,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":14110307209,\"order_id\":6145283795,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":1,\"trade_price\":12172,\"trade_turnover\":100,\"trade_fee\":-0.000001643115346697,\"offset_profitloss\":-0.000042670734165,\"create_date\":1565339616002,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":14110018718,\"order_id\":6145283794,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":3,\"trade_price\":12235.55,\"trade_turnover\":300,\"trade_fee\":-0.000007355615399389,\"offset_profitloss\":0,\"create_date\":1565339404561,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":14110018718,\"order_id\":6145283794,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":2,\"trade_price\":12235.55,\"trade_turnover\":200,\"trade_fee\":-0.000004903743599592,\"offset_profitloss\":0,\"create_date\":1565339404561,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13987256086,\"order_id\":6145283786,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12160.7,\"trade_turnover\":500,\"trade_fee\":-0.000012334816252353,\"offset_profitloss\":-0.0000528793012335,\"create_date\":1565254806989,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13981513305,\"order_id\":6145283785,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12176.36,\"trade_turnover\":500,\"trade_fee\":-0.000012318952461983,\"offset_profitloss\":0,\"create_date\":1565251202120,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13940384779,\"order_id\":6145283784,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12222.6,\"trade_turnover\":500,\"trade_fee\":-0.000008181565297072,\"offset_profitloss\":-0.0000349118214695,\"create_date\":1565223329559,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13940081556,\"order_id\":6145283783,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12233.04,\"trade_turnover\":500,\"trade_fee\":-0.000012261874399168,\"offset_profitloss\":0,\"create_date\":1565223147392,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13939991751,\"order_id\":6145283782,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12225.17,\"trade_turnover\":500,\"trade_fee\":-0.000008179845351843,\"offset_profitloss\":-0.0001983643607985,\"create_date\":1565223089907,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13938865611,\"order_id\":6145283781,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":4,\"trade_price\":12284.99,\"trade_turnover\":400,\"trade_fee\":-0.000009768017719184,\"offset_profitloss\":0,\"create_date\":1565222427099,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13938865611,\"order_id\":6145283781,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":12283.8,\"trade_turnover\":100,\"trade_fee\":-0.000002442241000341,\"offset_profitloss\":0,\"create_date\":1565222427099,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13931388082,\"order_id\":6145283780,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12212.75,\"trade_turnover\":500,\"trade_fee\":-0.000012282246013387,\"offset_profitloss\":0.0003822111815365,\"create_date\":1565217926937,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13920497358,\"order_id\":6145283779,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12099.79,\"trade_turnover\":500,\"trade_fee\":-0.000008264606245232,\"offset_profitloss\":0,\"create_date\":1565211628377,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13918362714,\"order_id\":6145283777,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":11991.93,\"trade_turnover\":500,\"trade_fee\":-0.000012508411907007,\"offset_profitloss\":0.0001561038749945,\"create_date\":1565210607133,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13918200990,\"order_id\":6145283776,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11947.2,\"trade_turnover\":500,\"trade_fee\":-0.000012555243069505,\"offset_profitloss\":0,\"create_date\":1565210546867,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13918030035,\"order_id\":6145283775,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":2,\"trade_price\":12015.34,\"trade_turnover\":200,\"trade_fee\":-0.000004993616493582,\"offset_profitloss\":0.0001387674450242,\"create_date\":1565210486778,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13918030035,\"order_id\":6145283775,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":3,\"trade_price\":12015.34,\"trade_turnover\":300,\"trade_fee\":-0.000007490424740373,\"offset_profitloss\":0.0002081511675363,\"create_date\":1565210486778,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13917861099,\"order_id\":6145283774,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11916,\"trade_turnover\":500,\"trade_fee\":-0.000012588116817724,\"offset_profitloss\":0,\"create_date\":1565210426565,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13917685468,\"order_id\":6145283773,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12048.52,\"trade_turnover\":500,\"trade_fee\":-0.000008299774578122,\"offset_profitloss\":-0.000343079941122,\"create_date\":1565210366937,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13916690229,\"order_id\":6145283772,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":2,\"trade_price\":12148.96,\"trade_turnover\":200,\"trade_fee\":-0.000003292462893943,\"offset_profitloss\":0,\"create_date\":1565209827025,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13916689582,\"order_id\":6145283772,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":12148.96,\"trade_turnover\":100,\"trade_fee\":-0.000002469347170457,\"offset_profitloss\":0,\"create_date\":1565209826566,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13916689582,\"order_id\":6145283772,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":12148.96,\"trade_turnover\":100,\"trade_fee\":-0.000002469347170457,\"offset_profitloss\":0,\"create_date\":1565209826566,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13916689582,\"order_id\":6145283772,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":1,\"trade_price\":12148.95,\"trade_turnover\":100,\"trade_fee\":-0.000002469349203017,\"offset_profitloss\":0,\"create_date\":1565209826566,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13906783050,\"order_id\":6145283771,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":11970.88,\"trade_turnover\":500,\"trade_fee\":-0.00001253040712128,\"offset_profitloss\":-0.0000331901761195,\"create_date\":1565203526366,\"role\":\"Taker\",\"order_source\":\"api\"},{\"match_id\":13901429255,\"order_id\":6145283770,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":11980.4,\"trade_turnover\":500,\"trade_fee\":-0.000008346966712296,\"offset_profitloss\":0,\"create_date\":1565199926461,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13878090563,\"order_id\":6145283765,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"sell\",\"offset\":\"close\",\"trade_volume\":5,\"trade_price\":12335.21,\"trade_turnover\":500,\"trade_fee\":-0.000008106874548548,\"offset_profitloss\":0.0003128643092965,\"create_date\":1565187331742,\"role\":\"Maker\",\"order_source\":\"api\"},{\"match_id\":13871580249,\"order_id\":6145283764,\"symbol\":\"BTC\",\"contract_type\":\"quarter\",\"contract_code\":\"BTC190927\",\"direction\":\"buy\",\"offset\":\"open\",\"trade_volume\":5,\"trade_price\":12240.73,\"trade_turnover\":500,\"trade_fee\":-0.000012254171115611,\"offset_profitloss\":0,\"create_date\":1565183726811,\"role\":\"Taker\",\"order_source\":\"api\"}],\"total_page\":3,\"current_page\":1,\"total_size\":124},\"ts\":1565710903339}";
                JSONObject jsonObject = JSONObject.parseObject(matchresults);
                if("ok".equals(jsonObject.getString("status"))){
                    JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("trades");
                    List<ContractMatch> resultList = new ArrayList<>();
                    for(int i=0;i<jsonArray.size();i++){
                        JSONObject json = jsonArray.getJSONObject(i);
                        ContractMatch contractMatch = new ContractMatch(json);
                        resultList.add(contractMatch);
                    }
                    contractMatchService.insertBatch(resultList);
                }
            } catch (Exception e) {
                e.printStackTrace();
                return  JsonUtil.getFailJsonObject();
            }
        }
        return JsonUtil.getSuccessJsonObject();
    }
}
